package com.mygo.designPattern.behavioral.strategicDesignPattern;

import com.mygo.designPattern.behavioral.strategicDesignPattern.discount.NoDiscountStrategy;
import com.mygo.designPattern.behavioral.strategicDesignPattern.discount.TenPercentDiscountStrategy;
import com.mygo.designPattern.behavioral.strategicDesignPattern.discount.TwentyPercentDiscountStrategy;

import java.math.BigDecimal;

public class StrategyPatternDemo {
    public static void main(String[] args) {
        // 创建购物车并使用无折扣策略
        ShoppingCart cart = new ShoppingCart(new NoDiscountStrategy());
        BigDecimal total = cart.calculateTotal(BigDecimal.valueOf(100));
        System.out.println("无折扣总价: " + total);

        // 切换到 10% 折扣策略
        cart.setDiscountStrategy(new TenPercentDiscountStrategy());
        total = cart.calculateTotal(BigDecimal.valueOf(100));
        System.out.println("10% 折扣总价: " + total);

        // 切换到 20% 折扣策略
        cart.setDiscountStrategy(new TwentyPercentDiscountStrategy());
        total = cart.calculateTotal(BigDecimal.valueOf(100));
        System.out.println("20% 折扣总价: " + total);
    }
}